<template>
  <div class="login_container">
    <div class="login_box">
      <!-- 头像 -->
      <div class="pic_box">
        <img src="../assets/static/img/b14.png" />
      </div>
      <!-- 表单 -->
      <el-form ref="loginFormRef" label-width="0" :rules="Rules" 
      class="login_form" :model="loginForm" >
          <!-- 账号 -->
        <el-form-item prop="username">
          <el-input prefix-icon="iconfont icon-user" v-model="loginForm.username" ></el-input>
        </el-form-item>
     

      <!-- 密码 -->
      
        <el-form-item prop ="password">
          <el-input type="password" prefix-icon="iconfont icon-3702mima" v-model="loginForm.password"></el-input>
        </el-form-item>
      
      <!-- 按键 -->

      <el-form-item class="login_btn">
          <el-button  type="primary" @click="loginsubmit">提交</el-button>
          <el-button type="info" @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
    </div>
  </div>
</template>

<script>

export default {
    data(){
        return {
          // 登录数剧的绑定对象
            loginForm:{
                username:'admin',
                password:'123456'
            },
            // 验证规则

           Rules:{
                // 验证账号
           username:[
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            // blur= 模糊 , trigger= 触发,扳机
            { min: 3, max: 10, message: '长度在 3 到 5 个字符', trigger: 'blur' } ],
                // 验证密码
                // userpwd:[{
           password:[
             { required: true, message:'密码输入错误', trigger:'blur'},
             { min:3, max:15, message:'长度在 3 到 15 个字符', trigger: 'blur'}


           ]       
                // }]
               
            }
        }
    },
    methods:{
        loginsubmit(){
          this.$refs.loginFormRef.validate(async vali =>{
            
          if(!vali) return;
           const {data:res } =await this.$http.post('login', this.loginForm)
           
           if(res.meta.status !== 200) return this.$message.error('登录失败')
           this.$message.success('登录成功')
            window.sessionStorage.setItem('token',res.data.token)
            // console.log(res.data.token);
            this.$router.push('/home')
          })
        },
        resetForm(){
         this.$refs.loginFormRef.resetFields();
        
         
         
        }
    }
};
</script>

<style lang ="less" scoped>
.login_container {
  background-color: #6aa090;
  height: 100%;
}

.login_box {
  width: 450px;
  height: 300px;
  background-color: rgb(255, 255, 255);
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);



  .pic_box {
    height: 130px;
    width: 130px;
    /* border: pink 1px solid; */
    padding: 5px;
    border-radius: 50%;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(#fff 50%, #6aa090 50%);
    box-shadow: 0 0 5px rgb(143, 226, 161);

    img {
      height: 100%;
      width: 100%;
    }
  }
}
.login_btn{
    display: flex;
    justify-content: flex-end;
}

  .login_form {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
  }
</style>